package com.softaria.promosite.client;

import java.util.List;
import java.util.Map;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.softaria.gwt.common.client.widget.Info;
import com.softaria.windows.logic.HelpWriter;
import com.softaria.windows.model.Size;
import com.softaria.windows.model.SizeCalculator;
import com.softaria.windows.model.View;
import com.softaria.windows.view.BadViewUrlException;
import com.softaria.windows.view.TypedViewFactory;
import com.softaria.windows.view.ViewCloseListenerRegistrator;
import com.softaria.windows.widgets.FrameResizeListenerRegistrator;

public class ManyWidgetsTypedViewFactory implements TypedViewFactory {

  public View createView(Map<String, List<String>> params,
      ViewCloseListenerRegistrator closeListenerRegistrator, FrameResizeListenerRegistrator frlr,
      final HelpWriter helpWriter) throws BadViewUrlException {

    View view = new View();

    view.setName("Set of GWT widgets");

    view.setSizeCalculator(new SizeCalculator() {

      public Size calculateSize(int width, int height) {
        return new Size() {

          public int getHeight() {
            return 250;
          }

          public int getWidth() {
            return 150;
          }

        };
      }

    });

    VerticalPanel vp = new VerticalPanel();

    vp.setStylePrimaryName("grids");

    view.setContent(vp);

    Label l = new Label("Just a label");

    vp.add(l);

    Button b1 = new Button("Button");
    b1.addClickHandler(new ClickHandler() {

      public void onClick(ClickEvent event) {
        Info.show("Wow!", "Button is clickable!");

      }

    });

    vp.add(b1);

    final ListBox lb = new ListBox();
    lb.addItem("First item");
    lb.addItem("Second item");
    lb.addItem("Third item");

    lb.addChangeHandler(new ChangeHandler() {

      public void onChange(ChangeEvent event) {
        Info.show("List box", "Current value is " + lb.getItemText(lb.getSelectedIndex()));
      }

    });

    vp.add(lb);

    return view;
  }
}
